package csel.model;

public class HurtPlayer extends TimedEffect implements java.io.Serializable
{
	private static final long serialVersionUID = 1L;
	int tickCount;
	int rate;

	public HurtPlayer()
	{

	}

	public HurtPlayer(int rate)
	{
		tickCount = 0;
		this.rate = rate;
	}

	protected void doEffect(Entity e)
	{
		// damage is greater than total life
		if (e.getLifeLeft() >= e.getLife())
		{
			e.setLifeLeft(0); // damage
			// game over stop thread?
			if (e.getLives() <= 0)
			{
				ChronoTrigger.getInstance().stop();
			} else
			{
				e.setLives(e.getLives() - 1);
			}
		} else
		{
			e.setLifeLeft(e.getLifeLeft() + rate);
		}
		tickCount = 0;
		System.out.println("Hurt for " + rate + " damage.");
	}

	public void tick()
	{
		if (tickCount >= 20)
		{
			this.doEffect(e);
		}
		tickCount++;
	}
}
